<template>
  <div class="cus-tab-list">
    <div
      class="tab"
      :class="active == index ? 'tab-active' : ''"
      v-for="(item, index) in tabList"
      :key="index"
      @click="tabClick(item, index)"
    >
      {{ item.label }}
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tabList: {
      type: Array,
      default: () => {
        return []
      }
    },
    current: {
      type: [Number, String],
      default: 0
    }
  },
  watch: {
    current: {
      deep: true,
      handler(val) {
        this.active = val
      }
    }
  },
  data() {
    return {
      active: 0
    }
  },
  methods: {
    tabClick(item, index) {
      if (this.active == index) return
      this.active = index
      this.$emit('tabClick', { ...item, index })
    }
  }
}
</script>

<style lang="scss" scoped>
.cus-tab-list {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  border-radius: 2px;
  background: rgba(41, 60, 98, 0.39);
  padding: 2px;
  height: 22px;
  line-height: 22px;
  .tab {
    color: #77a6ff;
    font-size: 13px;
    font-weight: 400;
    display: flex;
    align-items: center;
    padding: 0 8px;
    cursor: pointer;
    border-radius: 2px;
  }
  .tab.tab-active {
    background: #5796ff;
    color: #21427D;
    font-weight: bold;
  }
}
</style>
